<?php

namespace Modules\Core\Providers;

use Illuminate\Support\ServiceProvider;
// use App\Services\ShortMessageService ;

class CoreServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap the application services.
     *
     * @return void
     */
    public function boot()
    {
        require __DIR__.'/../Routes/api.php';

        app('Dingo\Api\Exception\Handler')->register(function (\Symfony\Component\HttpKernel\Exception\HttpException $exception) {
            $exception->setHeaders([
                'Access-Control-Allow-Origin' => '*'
            ]);
            return [];
        });
    }

    /**
     * Register the application services.
     *
     * @return void
     */
    public function register()
    {
        // $this->app->singleton('ShortMessageService', function($app){
        //     return new ShortMessageService() ;
        // }) ;

        $this->app->singleton('Message', function () {
            return new \Modules\Core\Services\MessageService();
        });

        $this->app->singleton('Auth', function () {
            return new \Modules\Core\Services\AuthService();
        });

        $this->app->singleton('Asset', function () {
            return new \Modules\Core\Services\AssetService();
        });

        $this->app->singleton('Miniapp', function () {
            return new \Modules\Core\Services\MiniappService();
        });

        $this->app->singleton('Wechat', function () {
            return new \Modules\Core\Services\WechatService();
        });

        $this->app->singleton('ByteDance', function () {
            return new \Modules\Core\Services\ByteDanceService();
        });

        $this->app->singleton('Kuaishou', function () {
            return new \Modules\Core\Services\KuaishouService();
        });

        $this->app->singleton('Alipay', function () {
            return new \Modules\Core\Services\AlipayService();
        });

        $this->app->singleton('Stats', function () {
            return new \Modules\Core\Services\StatsService();
        });

        $this->app->singleton('Payment', function () {
            return new \Modules\Core\Services\PaymentService();
        });

        $this->app->singleton('Setting', function () {
            return new \Modules\Core\Services\SettingService();
        });

        $this->app->singleton('ShortMessageService', function($app){
            return new \Modules\Core\Services\ShortMessageService();
        }) ;

        $this->app->singleton('ThrowExceptionService', function () {
            return new \Modules\Core\Services\ThrowExceptionService();
        });
    }
}
